%------------------------------------------------------------------
%------------------------------------------------------------------
%   Author: Md. Sazzad Hussain (sazzad.hussain@sydney.edu.au)
%   Learning and Affect Technologies Engineering (LATTE)
%   University of Sydney, 2011
%------------------------------------------------------------------
%------------------------------------------------------------------

% %Top Module (Main)
clc;
clear all;

%% Toolbox Set
% rehash toolbox;
% clear classes;
codePath='Z:\Drive 1\USYD Research\sazzadPhD_SVN';
p = genpath([codePath, '\lib']);
addpath(p);%library path
q = genpath([codePath,'\myFramework']);
addpath(q);%framework path

%% files I/O
% %location for input and output files
%dir for input files
global indir;
indir='Z:\Drive 1\USYD Research\NICTA Experiment 2010\NICTA_Exp1_Physio MAT Files';
%dir for output files
global outdir;
outdir='C:\Users\Sazzad Hussain\Desktop\New folder';
%% subject IDs
%subject ID from experiment

subjectID=[
%%IAPS 2010 Experiment
% 'siento_iaps_sub1_2010-09-06'         %AT
% % 'siento_iaps_sub1_2010-09-07'     %bad GSR
% % 'siento_iaps_sub1_2010-09-08'       %iaps only (rejected AT)
% % 'siento_iaps_sub1_2010-09-10'       %EMG bad, over aged)
% % 'siento_iaps_sub1_2010-09-13'       %bad EMG
% 'siento_iaps_sub1_2010-09-14'         %AT
% 'siento_iaps_sub1_2010-09-15'         %AT
% % 'siento_iaps_sub2_2010-09-15'         %iaps only 
% 'siento_iaps_sub1_2010-09-16'         %AT
% 'siento_iaps_sub2_2010-09-16'         %AT
% 'siento_iaps_sub1_2010-09-17'         %AT
% 'siento_iaps_sub1_2010-09-20'         %AT
% 'siento_iaps_sub2_2010-09-20'         %AT
% 'siento_iaps_sub1_2010-09-21'         %AT (not used for mapping)
% 'siento_iaps_sub1_2010-09-23'         %AT
% 'siento_iaps_sub2_2010-09-23'         %AT%%%resp crash after 104
% 'siento_iaps_sub1_2010-09-24'         %AT
% 'siento_iaps_sub1_2010-09-29'         %AT
% 'siento_iaps_sub1_2010-09-30'         %AT
% 'siento_iaps_sub2_2010-09-30'         %AT
% 'siento_iaps_sub1_2010-10-13'         %AT
% %------------------------------------------------------------------------
% %NICTA 2010 Experiment
'nicta1_sub1_2010-11-08'
% 'nicta1_sub1_2010-11-09'
% 'nicta1_sub1_2010-11-10'%eyefeat
% 'nicta1_sub1_2010-11-11'%eyefeat
% 'nicta1_sub1_2010-11-12'%eyefeat
% 'nicta1_sub1_2010-11-15'%eyefeat
% 'nicta1_sub1_2010-11-16'%eyefeat
% 'nicta1_sub2_2010-11-08'%eyefeat
% 'nicta1_sub2_2010-11-09'%eyefeat
% 'nicta1_sub2_2010-11-10'%eyefeat
% 'nicta1_sub2_2010-11-11'%eyefeat
% 'nicta1_sub2_2010-11-12'%eyefeat
% 'nicta1_sub2_2010-11-15'%eyefeat
% 'nicta1_sub2_2010-11-16'%eyefeat
% 'nicta1_sub3_2010-11-08'%eyefeat
% 'nicta1_sub3_2010-11-09'%eyefeat
% 'nicta1_sub3_2010-11-10'
% 'nicta1_sub3_2010-11-15'
% 'nicta1_sub3_2010-11-16'
% 'nicta1_sub4_2010-11-16'%eyefeat
 ];

%% configure physio/channels
% % window size, sampling rate, downsample size
winSizeECG=12;  %ECG
winSizeGSR=12;  %GSR
winSizeResp=12; %RESP
% winSizeEMG=12;  %EMG
sRate=1000; %original sample rate
dSample=5;  %downsample 

%% Biosignal Inspector
% % %shows physiological signals with face video for given annotations
% % a. load physio file, load video file, load annotation file
% % b. show all annotation instances
% % c. sync physio & video with annotation time chunk  
% workDir=pwd;
% subjectID;
% fid=fopen([workDir '\siento_bioSigInsp\linkFile.txt'],'w');%open file
% fprintf(fid, '%s\n', 'SubjectID');
% for m=1:length(subjectID(:,1))
%     fprintf(fid, '%s\n', subjectID(m,:));%baseline duration
% end
% fclose(fid);%close file
% 
% %load GUI
% siento_biosigInspector1

%% run self report stat program (IAPS)
% mode=2; %mode-1 (IAPS), mode-2 (AutoTutor)
% statExt1=stat_selfReport(mode,subjectID,indir,outdir);
% if statExt1==1 
%     disp('StatIAPS COMPLETE');
% end
%note: use original self report format

%% run self report stat program (IAPS-Cognitive load)
% statExt2=stat_emoCog(subjectID,indir,outdir);
% if statExt2==1 
%     disp('Stat IAPS-Cognitive COMPLETE');
% end

%% run doubleVid format to matlab format converter
% status=doubleVid_converter(subjectID,indir,outdir)
% if status==1 
%     disp('Conversion COMPLETE');
% end

%% feature extraction from IAPS
% featExt1=iapsFeatEx(subjectID,indir,winSizeECG,winSizeGSR,... 
% winSizeEMG,winSizeResp,sRate,dSample,outdir);
% if featExt1==1 
%     disp('Feat Ext COMPLETE (IAPS)');
% end

%note: check aubtProxy

%% feature extraction from AutoTutor
% featExt2=autoTutorFeatEx(subjectID,indir,winSizeECG,winSizeGSR,... 
% winSizeEMG,winSizeResp,sRate,outdir);
% if featExt2==1 
%     disp('Feat Ext COMPLETE (AutoTutor)');
% end
%note: check aubtProxy

%% feature extraction from IAPS-congnitiveLoad
featExt3=EmoCogFeatEx(subjectID,indir,winSizeECG,winSizeGSR,...
winSizeResp,sRate,dSample,outdir);
if featExt3==1 
    disp('Feat Ext COMPLETE (EmoCog)');
end
%note: check aubtProxy

%% self report extraction from IAPS-congnitiveLoad
% [ar_self,cl_self,cl_score,cl_resp,ar_cat,cl_cat,t_stamp,srExt]=siento_EmoCogSREx(subjectID,indir,outdir);
% 
% if srExt==1 
%     disp('SR Ext COMPLETE (EmoCog)');
% end
% ar_self
% cl_self
% cl_score
% cl_resp
% ar_cat
% cl_cat
% t_stamp
% 
% % x=[ar_self,cl_self,cl_score]

%% CSV to Mat convertor
% %dump CSV weka format files in indir and find converted MAT files in outdir
% numClasses=1;%total number of class col in file
% setClass=1;%col number (from left) for selected class 
% conv=csv2mat(indir, outdir, numClasses, setClass)
% if conv==1 
%     disp('CSV to MAT conversion complete');
% end

%% calculate feature trend
% % dump MAT format files in indir for featTrend()
% nameFile='trend_cl5_IAPS';
% featList={%list of fetures for analysis
% % %Basic Features
% 'ecgHrv-mean'
% % 'ecgR-mean'
% % 'ecgHrv-specRange1'
% % 'ecgHrvDistr-mean'
% 'sc-mean'
% % 'sc1Diff-mean'
% % 'sc2Diff-mean'
% 'rspPulse-mean'
% 'rsp-specRange1'
% % 'rspPulse-median'
% % 'rspPulse1Diff-mean'
% % 'rspPulse2Diff-mean'
% };
% 
% % %-----****---------------
% labelList={%list of classes
% % %Dimensional
% %     'HighValence-HighArousal'
% %     'HighValence-LowArousal'
% %     'HighValence-MediumArousal'
% %     'LowValence-HighArousal'
% %     'LowValence-LowArousal'
% %     'LowValence-MediumArousal'
% %     'MediumValence-HighArousal'
% %     'MediumValence-LowArousal'
% %     'MediumValence-MediumArousal'
% % %Arousal
% %     'LowArousal'
% %     'MediumArousal'
% %     'HighArousal'
% % %Valence
% %     'LowValence'
% %     'MediumValence'
% %     'HighValence'
% % %Cognitive Load
%     'NA'
%     '1'
%     '2'
%     '3'
%     '4'
%     '5'
%     };
% featT=featTrend(indir,outdir,featList,nameFile,labelList)
% if featT==1
%     disp('Feature Trend Complete!!');
% end

%% Run Classifier
% %dump MAT format files in indir for runClassifier()
% %set to same random seeds
% s = RandStream('mt19937ar','seed',0);
% RandStream.setDefaultStream(s);
% runs=1;%number of runs in random mode
% 
% % select features (modality)
% featRange=[
%     %change this accrding to dataset
% % %     % %emotion
% % %     '001:214'   %all   (all ch features; always on top)
% % %     '001:084'   %ecg   
% % %     '085:105'   %gsr 
% % %     '106:147'   %emg
% % %     '148:214'   %resp 
%     % %cognitive
%     '001:183'   %all   (all ch features; always on top)
% %     '001:084'   %ecg   
% %     '085:105'   %gsr 
% %     '106:172'   %resp
% %     '173:181'   %eye 
%     ];
% 
% % %classifier specification
% % w1 = ldc;               % Linear Discriminant Analysis
% % w2 = qdc;               % Quad Discriminant Analysis
% w3=svc;
% % w3 = svc([],'p',1);     % Linear kernel Support Vector
% % w4 = svc([],'p',2);     % non-Linear poly degree 2 Support Vector
% % w4 = knnc([],3);        % k-nearest neighbour (k=3) 
% 
% w=[w3];
% W=votec(w);%voting combining classfier
% 
% % % %AROUSAL Classfication
% % % for runClassify=1:runs
% % %     %file identifier
% % %     nameFile='IAPS_arousal_gv_neg';
% % %     %dir for input files
% % %     indir='D:\USYD_Research\Research Data\IAPS Journal\MAT Files\IAPS_ar_gv';
% % %     %dir for output files
% % %     outdir='D:\USYD_Research\Research Data\IAPS Journal\Results\Classification';
% % %     %run classification
% % %     classify1=runClassifierDF(indir,outdir,featRange,W,nameFile,runClassify);
% % % end
% % 
% % % %VALENCE Classfication
% % % for runClassify=1:runs %number of trials (crossval random)
% % %     %file identifier
% % %     nameFile='IAPS_valence_gv_2';
% % %     %dir for input files
% % %     indir='D:\USYD_Research\Research Data\IAPS Journal\MAT Files\IAPS_val_gv';
% % %     %dir for output files
% % %     outdir='D:\USYD_Research\Research Data\IAPS Journal\Results\Classification';
% % %     %run classification
% % %     classify2=runClassifierDF(indir,outdir,featRange,W,nameFile,runClassify);
% % % end
% 
% %COGNITIVE LOAD Classfication
% for runClassify=1:runs %number of trials (crossval random)
%     %file identifier
%     nameFile='MMCogEmS_testAll';
%     %dir for input files
%     indir='D:\USYD Research\Research Data\MMCogEmS2011\featMat';
%     %dir for output files
%     outdir='D:\USYD Research\Research Data\MMCogEmS2011\Classification';
%     %run classification
%     classify3=runClassifierDF(indir,outdir,featRange,W,nameFile,runClassify);
% end
% 
% % % % classification1 complete
% % % if classify1==1
% % %     disp('Classification1 Complete!!');
% % % end
% % 
% % % % classification2 complete
% % % if classify2==1
% % %     disp('Classification2 Complete!!');
% % % end
% 
% % classification3 complete
% if classify3==1
%     disp('Classification3 Complete!!');
% end

%% Statistical Test
% % rehash toolbox
% % clear classes
% h=[
% 0.5714
% 0.5
% 0.25
% 0.1429
% 0.5714
% 0.6429
% 0.6429
% 0.5714
% 0.4643
% 0.5714
% 0.7143
% 0.1429
% 0.5
% 0.1786
% 0.25  
% ];
% 
% p=[
% 0.4643
% 0.0357
% 0.1071
% 0.4286
% 0.8571
% 0.5
% 0.5714
% 0.5
% 0.1786
% 0.0714
% 0.7143
% 0.6071
% 0.0714
% 0.5
% 0.5357
% ];
% 
% c=[
% 0.6429
% 0.4643
% 0.2857
% 0.4643
% 0.8214
% 0.75
% 0.6071
% 0.6071
% 0.3214
% 0.75
% 0.75
% 0.6071
% 0.3929
% 0.5357
% 0.5
% ];
% 
% %copy col for statistical significance tests
% x=[h p c];
% % % one-way ANOVA
% [p,tbl,stats] = anova1(x)
% % % post-hoc analysis
% [c,m,h,nms] = multcompare(stats,'ctype','lsd' );

%% Toolbox clear
rmpath(p);
rmpath(q);